var pageii = null;
var grid = null;
$(function() {
	
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
		}, {
			colkey : "code",
			name : "物料编号",
		}, {
			colkey : "name",
			name : "物料名称",
		}, {
			colkey : "specification",
			name : "物料规格",
		}],
		jsonUrl : rootPath + '/item_resource/bom_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		checkValue: "id",
		records: "list",
		totalPages: "pages",
		totalRecords: "total",
		pagecode: '10',
		pageNow : 'pageNum'
	});



	//根据下拉框选取物料

	$("#material").change(function() {

		var sel = $("#material option:selected").val();//获取下拉框数据
		if(sel == 0){
			$("#searchForms").val("0")
			var searchParams = $("#searchForms").serializeJson();
			grid.setOptions({
				data : searchParams
			});
		}else if (sel == 2) {
			$("#searchForms").val("2")
			var searchParams = $("#searchForms").serializeJson();
			grid.setOptions({
				data : searchParams
			});
		}else if(sel == 3){
			$("#searchForms").val("3")
			var searchParams = $("#searchForms").serializeJson();
			grid.setOptions({
				data : searchParams
			});
		}else if(sel == 5){
			$("#searchForms").val("5")
			var searchParams = $("#searchForms").serializeJson();
			grid.setOptions({
				data : searchParams
			});
		}else{
			$("#searchForms").val("1")
			var searchParams = $("#searchForms").serializeJson();
			grid.setOptions({
				data : searchParams
			});
		}
	});


	//搜索物料
    $("#search").click("click", function() {
        // var searchParams = $("#deviceName").serializeJson();
        var paramName = $("#paramName").val();
        var paramValue = $("#paramValue").val();
        grid.setOptions({
            // data : searchParams
            data : {"paramName":paramName,"paramValue":paramValue}
        });
    });


    $("#ok").click("click", function() {
        cobx_elect();
    });
	
});

function cobx_elect() {
    var checkbox = grid.getSelectedCheckbox();
    if (checkbox.length > 1 || checkbox == "") {
    	console.log("sld")
        parent.layer.msg("请注意:勾选多个物料时只有最上面的有效",{time: 3000, icon:7});
    //	layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', {time: 5000, icon:6});
    }

    //获取选择的数据
    var cbox = grid.selectRow()[0];
    window.parent.inser_data(cbox.code,cbox.name);
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
    parent.layer.close(index);
}